<template>
	<!-- 外层容器区域 -->
	<view class="userinfo-container">
		<!-- 顶部盒子区域 -->
		<view class="top-box">
			<image :src="userInfo.avatarUrl" mode="" class="avatar"></image>
			<text class="nickName">{{ userInfo.nickName }}</text>
		</view>
		<!-- 面板列表区域 -->
		<view class="panel-list">
			<!-- 第一面板区域 -->
			<view class="panel">
				<!-- 第一面板内容区域 -->
				<view class="panel-body">
					<view class="panel-item">
						<text>8</text>
						<text>收藏店铺</text>
					</view>
					<view class="panel-item">
						<text>8</text>
						<text>收藏商品</text>
					</view>
					<view class="panel-item">
						<text>8</text>
						<text>关注商品</text>
					</view>
					<view class="panel-item">
						<text>8</text>
						<text>历史足迹</text>
					</view>
				</view>
			</view>
			<!-- 第二面板区域 -->
			<view class="panel">
				<!-- 第二面板标题区域 -->
				<view class="panel-title">我的订单</view>
				<!-- 第二面板内容区域 -->
				<view class="panel-body">
					<view class="panel-item">
						<uni-icons type="wallet" size="30"></uni-icons>
						<text>待付款</text>
					</view>
					<view class="panel-item">
						<uni-icons type="gift" size="30"></uni-icons>
						<text>待收货</text>
					</view>
					<view class="panel-item">
						<uni-icons type="paperplane" size="30"></uni-icons>
						<text>退款/退货</text>
					</view>
					<view class="panel-item">
						<uni-icons type="list" size="30"></uni-icons>
						<text>全部订单</text>
					</view>
				</view>
			</view>
			<!-- 第三面板区域 -->
			<view class="panel">
				<!-- 第三面板每一项区域 -->
				<view class="panel-list-item">
					<text>收货地址</text>
					<uni-icons type="forward" size="18"></uni-icons>
				</view>
				<view class="panel-list-item">
					<text>联系客服</text>
					<uni-icons type="forward" size="18"></uni-icons>
				</view>
				<view class="panel-list-item" @click="logout">
					<text>退出登录</text>
					<uni-icons type="forward" size="18"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	name: 'my-userinfo',
	data() {
		return {};
	},
	methods: {
		...mapMutations('m_user', ['updateAddree', 'saveUserInfo', 'saveToken']),
		// 退出登录
		logout() {
			const that = this;
			uni.showModal({
				title: '退出',
				content: '确认退出登陆吗？',
				success: function(res) {
					if (res.confirm) {
						that.updateAddree({});
						that.saveUserInfo({});
						that.saveToken('');
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		}
	},
	computed: {
		...mapState('m_user', ['userInfo'])
	}
};
</script>

<style lang="scss">
.userinfo-container {
	height: 100%;
	background-color: #f4f4f4;

	// 顶部盒子
	.top-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 400rpx;
		background-color: red;

		// 头像
		.avatar {
			width: 90px;
			height: 90px;
			border-radius: 50%;
			border: 2px solid #ffffff;
			box-shadow: 1px 4px 5px black;
		}

		// 昵称
		.nickName {
			margin-top: 10px;
			font-size: 13px;
			color: #ffffff;
			font-weight: bold;
		}
	}

	// 面板列表
	.panel-list {
		padding: 0 10px;
		position: relative;
		top: -10px;

		// 面板
		.panel {
			background-color: #ffffff;
			margin-bottom: 10px;
			font-size: 13px;

			// 面板标题
			.panel-title {
				font-size: 14px;
				line-height: 45px;
				margin-left: 10px;
				border-bottom: 1px solid #efefef;
			}

			// 面板内容
			.panel-body {
				display: flex;
				justify-content: space-around;
				height: 120rpx;

				// 面板每一项
				.panel-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					line-height: 20px;
				}
			}
			// 第三面板每一项
			.panel-list-item {
				display: flex;
				justify-content: space-between;
				padding: 0 10px;
				line-height: 40px;
				align-items: center;
				border-bottom: 1px solid #efefef;
			}
		}
	}
}
</style>
